package com.kbt.ui;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * @project: kbt
 * @package: com.kbt.ui
 * @class:
 * @Desc:定义禁止滑动的ViewPager
 * @author: kuajie
 * @time: 15/8/1 11:19
 * @Version: 1.0
 */
public class NoScrollViewPager extends ViewPager {

    private boolean canScroller = false;

    public NoScrollViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

    public NoScrollViewPager(Context context) {
        super(context);
    }

    //设置是否可以滑动
    public void setScanScroll(boolean isCanScroll) {
        this.canScroller = isCanScroll;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (canScroller) {
            return super.onInterceptTouchEvent(ev);
        } else {
            return false;
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        if (canScroller) {
            return super.onTouchEvent(event);
        } else {
            return false;
        }
    }

    @Override
    public void scrollTo(int x, int y) {
        super.scrollTo(x, y);
    }

    @Override
    public void setCurrentItem(int item, boolean smoothScroll) {

        super.setCurrentItem(item, smoothScroll);

    }

    @Override
    public void setCurrentItem(int item) {
        super.setCurrentItem(item);
    }


}
